<template>
  <div class="headmy">
    {{ $store.state.a }}
    <!-- <button @click="$store.state.a++">改</button> -->
    <!-- <button @click="$store.commit('changea', 2)">改</button> -->
    <van-cell-group class="my-info" v-if="isLogin">
      <van-cell
        class="base-info"
        center
        :border="false"
        @click="$router.push('/user')"
      >
        <van-image
          class="avatar"
          slot="icon"
          round
          fit="cover"
          :src="userInfo.avatar"
        />
        <div class="name" slot="title">{{ userInfo.nickname }}</div>
        <van-button class="update-btn" size="small" round>编辑资料</van-button>
      </van-cell>
      <van-grid class="data-info" :border="false" column-num="2">
        <van-grid-item class="data-info-item">
          <div slot="text" class="text-wrap">
            <div class="count">{{ publish_num }}</div>
            <div class="text">头条</div>
          </div>
        </van-grid-item>
        <van-grid-item class="data-info-item">
          <div class="text-wrap" slot="text">
            <div class="count">{{ liked_num }}</div>
            <div class="text">获赞</div>
          </div>
        </van-grid-item>
      </van-grid>
    </van-cell-group>

    <!-- 未登录 -->
    <div class="not-login" v-else @click="$router.push('/login')">
      <div>
        <img class="mobile" src="~@/assets/tel.png" />
      </div>
      <div class="text">登录 / 注册</div>
    </div>
    <van-grid clickable :column-num="2">
      <van-grid-item icon="star-o" text="收藏" to="/" />
      <van-grid-item icon="underway-o" text="历史" to="/" />
    </van-grid>

    <van-cell title="修改密码" is-link to="/modify" />
    <van-cell title="联系我们" is-link to="/contact" />
    <van-cell title="关于我们" is-link to="/about" />

    <van-button v-if="isLogin" type="primary" block @click="logout"
      >退出登录</van-button
    >

    <!-- 底部栏 -->
    <tabBar></tabBar>
  </div>
</template>
<script>
import Tabbar from "@/components/tabBar";
import { mapState, mapMutations } from "vuex";
import { Dialog } from "vant";
//做一个判断 如果没登陆 和登录后看到的界面 有所不同
export default {
  data() {
    return {};
  },
  computed: {
    ...mapState([
      "uid",
      "token",
      "isLogin",
      "userInfo",
      "publish_num",
      "liked_num",
    ]),
  },
  methods: {
    ...mapMutations(["clear"]),
    async logout() {
      let res = await Dialog.confirm({
        title: "标题",
        message: "您确认退出吗?",
      });

      if (res == "confirm") {
        localStorage.clear(); //清所有
        // localStorage.removeItem('token')//指定

        this.clear();
      }
    },
  },
  components: {
    [Tabbar.name]: Tabbar,
    [Dialog.Component.name]: Dialog.Component,
  },
};
</script>
<style lang="less">
.headmy {
  background-color: @color3;
  height: 100vh;
  .my-info {
    background: url("~@/assets/banner.jpg") no-repeat;
    background-size: cover;
    .base-info {
      box-sizing: border-box;
      height: 115px;
      background-color: unset;
      padding-top: 38px;
      padding-bottom: 11px;
      .avatar {
        box-sizing: border-box;
        width: 66px;
        height: 66px;
        border: 1px solid #fff;
        margin-right: 11px;
      }
      .name {
        font-size: 15px;
        color: #fff;
      }
      .update-btn {
        height: 18px;
        font-size: 12px;
        color: #666666;
      }
    }
    .data-info {
      .data-info-item {
        height: 65px;
        color: #fff;
        .text-wrap {
          display: flex;
          flex-direction: column;
          justify-content: center;
          align-items: center;
          .count {
            font-size: 18px;
          }
          .text {
            font-size: 11px;
          }
        }
      }
    }
    .van-grid-item__content {
      background-color: unset;
    }
  }

  .not-login {
    height: 180px;
    background: url("~@/assets/banner.jpg") no-repeat;
    background-size: cover;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    .mobile {
      width: 66px;
      height: 66px;
    }
    .text {
      font-size: 14px;
      color: #fff;
    }
  }

  .nav-grid {
    .nav-grid-item {
      height: 70px;
      .iconfont {
        font-size: 22px;
        margin-bottom: 5px;
      }
      .icon-shoucang {
        color: #eb5253;
      }
      .icon-lishi {
        color: #ff9d1d;
      }
      .van-grid-item__text {
        font-size: 14px;
        color: #333333;
      }
    }
  }

  .logout-cell {
    text-align: center;
    color: #d86262;
  }
  .mb-4 {
    margin-bottom: 4px;
  }
  .main {
    margin-top: 6px;
    .van-cell--clickable {
      margin-top: 1px;
    }
  }
  .van-button--block {
    top: 6px;
    background-color: #fff;
    width: 100%;
  }
  .van-button--primary {
    color: #dd7574;
    border: 1px solid #fff;
  }
}
</style>